package com.zhengshang.quartz.task;

import com.zhengshang.api.domain.AppActivity;
import com.zhengshang.api.mapper.AppActivityMapper;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("activityTask")
public class ActivityTask
{
    protected final Logger logger = LoggerFactory.getLogger(ActivityTask.class);
    @Autowired
    private AppActivityMapper appActivityMapper;

    public void autoStartActivity()
    {
        AppActivity appActivity = new AppActivity();
        appActivity.setActivityStartTime(DateUtils.getNowDate());
        List<AppActivity> appActivityList = appActivityMapper.selectWaitStartList(appActivity);
        for (AppActivity activity : appActivityList) {
            activity.setStatus("2");
            activity.setUpdateBy("admin");
            activity.setUpdateTime(DateUtils.getNowDate());
            appActivityMapper.updateAppActivity(activity);
        }
        logger.info("自动启动" + appActivityList.size() + "个即将开始的活动");
    }

    public void autoCloseActivity()
    {
        AppActivity appActivity = new AppActivity();
        appActivity.setActivityEndTime(DateUtils.getNowDate());
        List<AppActivity> appActivityList = appActivityMapper.selectWaitStartList(appActivity);
        for (AppActivity activity : appActivityList) {
            activity.setStatus("3");
            activity.setUpdateBy("admin");
            activity.setUpdateTime(DateUtils.getNowDate());
            appActivityMapper.updateAppActivity(activity);
        }
        logger.info("自动关闭" + appActivityList.size() + "个已结束的活动");
    }
}
